import requests
import openpyxl
import json

# url = "http://182.43.24.152:8081/api/front/login"
# json = {"account": "18292417675", "password": "crmeb@123456"}
# response = requests.post(url=url, json=json, headers={"application": "json"})
# print(response.text)


# 读取Excel表中数据

workbook = openpyxl.load_workbook("F:/Longlsland/API.xlsx")  # 获取这个路径下的文件
sheet = workbook['Sheet2']  # 获取Excel文件中的工作表
token = ""
for row in range(2, sheet.max_row + 1):
    reqUrl = sheet[f'D{row}'].value  # 地址
    reqType = sheet[f'E{row}'].value.lower()  # 请求类型
    reqParam = json.loads(sheet[f'H{row}'].value)  # 请求参数

    if reqType == "post":
        response = requests.post(url=reqUrl, json=reqParam)
        if response.status_code == 200:
            token = response.json()['data']['token']
        else:
            print("Error", response.status_code)
        sheet.cell(row=row, column=10, value=response.status_code)
    elif reqType == "get":
        pass
    else:
        break
workbook.save("F:/Longlsland/API.xlsx")
print("执行完成")
